<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dung
 * Date: 2/23/14
 * Time: 12:40 AM
 * To change this template use File | Settings | File Templates.
 */
?>
<div id="maincp">
    <h1 class="h1">Information Manager</h1>
    <ul class="list">
        <li><a href="index.php?p=addinformation" title="Add a information">Add Information</a></li>
    </ul>
    <p>This table will show all information in database.</p>
    <table class="datatable">
        <thead>
        <tr>
            <td>Name</td>
            <td>Language</td>
            <td>Action</td>
        </tr>
        </thead>
        <?php
        if (isset($_GET["page"])) {
            $page  = $_GET["page"];
        }else{
            $page=1;
        }
        $start = ($page-1) * 10;
        $information=InformationList($start);
        if(mysql_num_rows($information)!=0){
            while($row_information=mysql_fetch_array($information))
            {
                ob_start();
                ?>
                <tbody>
                <tr>
                    <td>{Name}</td>
                    <td>{Language}</td>
                    <td><a class="text-dung" href="index.php?p=editinformation&information_id={id}">Edit</a>
                        -
                        <a class="text-dung" href="index.php?p=deleteinformation&information_id={id}">Delete</a>
                    </td>
                </tr>
                </tbody>
                <?php

                $s= ob_get_clean();
                $s=str_replace("{id}",$row_information["information_id"],$s);
                $s=str_replace("{group}",$row_information["group"],$s);
                $s=str_replace("{Name}",$row_information["key"],$s);
                $s=str_replace("{Contents}",$row_information["value"],$s);
                $language=LanguageList();
                while($row_language=mysql_fetch_array($language)){
                   if($row_information['language_id']=$row_language['language_id']) {
                       $s=str_replace("{Language}",$row_language["name"],$s);
                   }
                }
                echo $s;
                ?>
            <?php
            }
        }else{ ?>
            <tbody>
            <tr>
                <td style="text-align: center" class="no-result" colspan="4">
                    <?php echo "No Result!"; ?>
                </td>
            </tr>
            </tbody>
        <?php
        }
        ?>
    </table>
    <table width="100%">
        <tr>
            <td>
                <?php
                $qr="SELECT COUNT(information_id) from dt_information";
                $result=mysql_query($qr);
                $row_result=mysql_fetch_array($result);
                $records=$row_result[0];
                $total_pages=ceil($records/10);
                if($total_pages>2){
                    echo "Pages ";
                    for ($i=1; $i<=$total_pages; $i++) {
                        echo "<a href='index.php?p=informationlist&page=".$i."'>".$i."</a> ";
                    }
                }?>
            </td>
        </tr>
    </table>
    <a href="index.php?p=cpanel" title="Back to Dashboard">&laquo; Back to Dashboard.</a>
</div>